package structural.decorator;

import structural.decorator.custom.Coffee;
import structural.decorator.custom.coffee.Latte;
import structural.decorator.custom.condiment.Ice;
import structural.decorator.custom.condiment.Milk;
import structural.decorator.custom.cupSize.BigCup;
import structural.decorator.java.LowerCaseInputStream;

import java.io.*;

/**
 * 装饰者模式
 * 动态地给对象增加一些职责，即增加其额外的功能。
 *
 * 优点：提供不同的组合方式，在应用时按需进行选择，累加
 * 缺点：类很多，无法限制使用时的装饰顺序
 */
public class Main {
    public static void main(String[] args) {
        Coffee coffee = new Latte();
        coffee = new Milk(coffee);
        coffee = new Ice(coffee);
        coffee = new BigCup(coffee);
        System.out.println("咖啡信息： ");
        System.out.println("介绍： " + coffee.getDescription());
        System.out.println("价格： " + coffee.cost());

        System.out.println("======");
        int c;
        try {
            String path = LowerCaseInputStream.class.getResource("/").getPath();
            System.out.println(path);
            InputStream in = new LowerCaseInputStream(new BufferedInputStream(new FileInputStream(path + "test.txt")));
            while ((c = in.read()) >= 0) {
                System.out.print((char) c);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
